package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Questionnaire;
import com.tanhua.model.mongo.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @author wjs
 * @version 1.0
 * @date 2022/1/9 0009 上午 8:49
 */
@DubboService
public class QuestionnaireApiImpl implements QuestionnaireApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Questionnaire> findAll() {
        return mongoTemplate.findAll(Questionnaire.class);
    }

    @Override
    public void save(Questionnaire questionnaire) {
        mongoTemplate.save(questionnaire);
    }

    @Override
    public Questionnaire findByQuestionsId(String s) {
        Questions questions = mongoTemplate.findById(new ObjectId(s), Questions.class);

        return mongoTemplate.findById(questions.getToQuestionnaireId(), Questionnaire.class);
    }
}
